myContracts = {"ZhangSan": 26482168412, "LiSi": 75641358145, "WangWu": 98214351124}
print("---------------Hello, this is my contracts operation system.---------------")
menu = ("###MENU:\n\t1-Show the contracts;\n\t2-Add;\n\t3-Delete;\n\t4-Find name by phone numbers;\n\t5-Find phone "
        "numbers by name\n##Enter operation num:")
while True:
    operation = int(input(menu))
    if operation == 1:  # Show the contracts
        count = 1
        for key in myContracts:
            print("({}).{}: {}".format(count, key, myContracts[key]))
            count += 1
        print("\n")
    elif operation == 2:    # Add
        addName = input("Please enter a NAME that you want to add: ")
        if addName in myContracts:
            print("--#RESULT: That NAME has existed.\n")
        else:
            addNum = input("Please enter its PHONE NUMBER: ")
            myContracts[addName] = addNum
            print("--#RESULT: Already added.\n")
    elif operation == 3:    # Delete
        delName = input("Please enter a NAME that you want to delete: ")
        if delName in myContracts:
            print("--#RESULT: Already deleted!\n", "item: ", delName, myContracts.pop(delName), "\n")
        else:
            print("--#RESULT: Name has not found.\n")
    elif operation == 4:    # Find name by phone numbers
        findNum = eval(input("Please enter a PHONE NUMBER that belongs to the person you want to find: "))
        if findNum in myContracts.values():
            for i in myContracts:
                if findNum == myContracts[i]:
                    print("--#RESULT: Its Name is:\n", i)
        else:
            print("--#RESULT: The PHONE NUMBER is not exist.\n")
    elif operation == 5:    # Find phone numbers by name
        findName = input("Please enter a Name that has a phone number in your contracts: ")
        if findName in myContracts:
            print("--#RESULT: {}'s phone number is {}\n".format(findName, myContracts[findName]))
        else:
            print("--#RESULT: The NAME is not exist.\n")
    else:
        print("###System closed.")
        break
